package al189rotate;

import java.util.Arrays;

public class RotateArray1 {

    public static void rotate(int[] nums, int k) {

        int length = nums.length;
        if(k>length){
            k %= length;
        }
        reverse(nums,0,length-1);
        reverse(nums,0,k-1);
        reverse(nums,k,length-1);
    }

    public static void reverse(int[] nums, int start, int end){
        int temp = 0;
        while (start < end){
            temp = nums[end];
            nums[end] = nums[start];
            nums[start] = temp;
            start ++;
            end --;
        }
    }

    public static void main(String[] args) {
        int[] nums = {1,2};
        rotate(nums,3);
        System.out.println(Arrays.toString(nums));
    }
}
